package com.dragee.modules.officialWebsite.controller;

import com.dragee.common.PageUtils;
import com.dragee.common.R;
import com.dragee.modules.officialWebsite.entity.GwAbouusEntity;
import com.dragee.modules.officialWebsite.service.GwAbouusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;



/**
 * 关于我们
 *
 * @author tc
 * @email tc@mail.com
 * @date 2023-07-11 21:05:13
 */
@RestController
@RequestMapping("officialWebsite/gwabouus")
@Api(tags = "关于我们")
public class GwAbouusController {
    @Autowired
    private GwAbouusService gwAbouusService;

    /**
     * 列表
     */
    @GetMapping("list")
    @ApiOperation("关于我们列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = gwAbouusService.queryPage(params);
        return R.ok().put("data", page);
    }


    /**
     * 信息
     */
    @GetMapping("{id}")
    @ApiOperation("关于我们信息")
    public R info(@PathVariable("id") Long id){
		GwAbouusEntity gwAbouus = gwAbouusService.getById(id);
        return R.ok().put("data", gwAbouus);
    }

    /**
     * 保存
     */
    @PostMapping("saveOrUpdate")
    @ApiOperation("保存或修改关于我们")
    public R saveOrUpdate(@RequestBody GwAbouusEntity gwAbouus){
        gwAbouusService.saveOrUpdate(gwAbouus);
        return R.ok();
    }


    /**
     * 删除
     */
    @GetMapping("delete-by-id")
    @ApiOperation("关于我们删除")
    public R delete( String id){
		gwAbouusService.removeById(Long.parseLong(id));
        return R.ok();
    }

    @GetMapping("delete-by-ids")
    @ApiOperation("关于我们批量删除")
    public R deletes(String ids){
        String[] idArr = ids.split(",");
        Arrays.stream(idArr).forEach(id -> gwAbouusService.removeById(Long.parseLong(id)));
        return R.ok();
    }

    @ApiOperation(value = "数据导入")
    @PostMapping("/import")
    public R importData(@RequestParam("file") MultipartFile file) throws IOException {
        return gwAbouusService.importData(file);
    }

    @ApiOperation(value = "数据导出")
    @GetMapping("/export")
    public void exportData(@RequestParam Map<String, Object> params, HttpServletResponse response ) throws Exception {
            gwAbouusService.exportData(params, response);
    }

}
